package com.operate.service;

import com.operate.bean.RiseProportion;
import com.operate.dao.GpMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: ZZZ
 */
@Slf4j
@Service
public class RiseProportionService {

    @Autowired
    private GpMapper gpMapper;

    public List<RiseProportion> riseProportionQuery() {
        List<RiseProportion> list = gpMapper.riseProportionQuery();

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM");
        String month = dtf.format(LocalDate.now());
        List<RiseProportion> list2 = new ArrayList<>();
        List<RiseProportion> list3 = new ArrayList<>();

        for (RiseProportion riseProportion : list) {
            if (riseProportion.getType().equals("1")) {
                RiseProportion sp = new RiseProportion();
                sp.setType("0");
                sp.setRiseNum(100 - riseProportion.getRiseNum());
                sp.setDay(riseProportion.getDay());
                list3.add(sp);
                if (riseProportion.getDay().startsWith(month)) {
                    RiseProportion rise = new RiseProportion();
                    rise.setType("3");
                    rise.setRiseNum(riseProportion.getRiseNum());
                    rise.setDay(riseProportion.getDay());
                    list2.add(rise);
                }
            }
        }
        list.addAll(list2);
        list.addAll(list3);
        list.addAll(gpMapper.comparePastIncreases());
        return list;
    }


}
